package com.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.netca.bmps.userservice.bo.CertInfo;
import net.netca.bmps.userservice.service.UserService;
import net.netca.bmps.userservice.servicelayer.UserServiceImpl;

public class QueryPersonalCertSlt extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public QueryPersonalCertSlt() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");
		
		//CertServiceClient client = new CertServiceClient("http://192.168.0.37:8082/businessmanage/services/CertService");
		//CertServicePortType service = client.getCertServiceHttpPort();
		
		UserService userService=new UserServiceImpl();
		
		int caid=-1;
		CertInfo info=null;
		RequestDispatcher rd=null;
		
		try {
			String action=request.getParameter("action");
			if(action==null||!"query".equalsIgnoreCase(action))
				throw new Exception("非法请求");
			int type=Integer.parseInt(request.getParameter("type"));
			String serialnum=request.getParameter("serialnum");
			String reqno=request.getParameter("reqno");
			if("".equalsIgnoreCase(reqno))
				throw new Exception("业务受理号为空");
			//info=service.getPersonalCert(reqno,type,serialnum);
			info=userService.getPersonalCert(reqno,type,serialnum);
			request.getSession().setAttribute("certlist",info);
			response.setCharacterEncoding("UTF-8");
			rd=request.getRequestDispatcher("../personalcertinstall.jsp");
			rd.include(request, response);
		} catch (NumberFormatException e) {
			e.printStackTrace();
			request.getSession().setAttribute("exception", e);
			response.sendRedirect("../showerror.jsp");
		} catch (Exception e) {
			e.printStackTrace();
			request.getSession().setAttribute("exception", e);
			response.sendRedirect("../showerror.jsp");
		}
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request,response);
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
